home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / sendmail / sendmail-5.65c+IDA-1.4.4.1 / src / RCS / macro.c,v < prev    next >
Encoding:
Text File  |  1991-06-25  |  8.8 KB  |  487 lines

  1. head    5.7;
  2. branch    5.7.0;
  3. access;
  4. symbols
  5.     RELEASE:5.7.0.7
  6.     BETA:5.7.0.7
  7.     UICSO:5.7.0
  8.     VANILLA:5.7;
  9. locks; strict;
  10. comment    @ * @;
  11.  
  12.  
  13. 5.7
  14. date    90.06.20.08.35.57;    author paul;    state Exp;
  15. branches
  16.     5.7.0.1;
  17. next    ;
  18.  
  19. 5.7.0.1
  20. date    90.06.20.09.43.04;    author paul;    state Exp;
  21. branches;
  22. next    5.7.0.2;
  23.  
  24. 5.7.0.2
  25. date    90.10.13.18.40.00;    author paul;    state Exp;
  26. branches;
  27. next    5.7.0.3;
  28.  
  29. 5.7.0.3
  30. date    91.02.17.02.39.09;    author paul;    state Exp;
  31. branches;
  32. next    5.7.0.4;
  33.  
  34. 5.7.0.4
  35. date    91.03.04.21.48.23;    author paul;    state Exp;
  36. branches;
  37. next    5.7.0.5;
  38.  
  39. 5.7.0.5
  40. date    91.04.05.14.55.15;    author paul;    state Exp;
  41. branches;
  42. next    5.7.0.6;
  43.  
  44. 5.7.0.6
  45. date    91.05.18.17.29.02;    author paul;    state Exp;
  46. branches;
  47. next    5.7.0.7;
  48.  
  49. 5.7.0.7
  50. date    91.05.20.02.40.07;    author paul;    state Exp;
  51. branches;
  52. next    ;
  53.  
  54.  
  55. desc
  56. @@
  57.  
  58.  
  59.  
  60. 5.7
  61. log
  62. @5.64 Berkeley release
  63. @
  64. text
  65. @/*
  66.  * Copyright (c) 1983 Eric P. Allman
  67.  * Copyright (c) 1988 Regents of the University of California.
  68.  * All rights reserved.
  69.  *
  70.  * Redistribution and use in source and binary forms are permitted provided
  71.  * that: (1) source distributions retain this entire copyright notice and
  72.  * comment, and (2) distributions including binaries display the following
  73.  * acknowledgement:  ``This product includes software developed by the
  74.  * University of California, Berkeley and its contributors'' in the
  75.  * documentation or other materials provided with the distribution and in
  76.  * all advertising materials mentioning features or use of this software.
  77.  * Neither the name of the University nor the names of its contributors may
  78.  * be used to endorse or promote products derived from this software without
  79.  * specific prior written permission.
  80.  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
  81.  * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
  82.  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  83.  */
  84.  
  85. #ifndef lint
  86. static char sccsid[] = "@@(#)macro.c    5.7 (Berkeley) 6/1/90";
  87. #endif /* not lint */
  88.  
  89. # include "sendmail.h"
  90.  
  91. /*
  92. **  EXPAND -- macro expand a string using $x escapes.
  93. **
  94. **    Parameters:
  95. **        s -- the string to expand.
  96. **        buf -- the place to put the expansion.
  97. **        buflim -- the buffer limit, i.e., the address
  98. **            of the last usable position in buf.
  99. **        e -- envelope in which to work.
  100. **
  101. **    Returns:
  102. **        none.
  103. **
  104. **    Side Effects:
  105. **        none.
  106. */
  107.  
  108. expand(s, buf, buflim, e)
  109.     register char *s;
  110.     register char *buf;
  111.     char *buflim;
  112.     register ENVELOPE *e;
  113. {
  114.     register char *xp;
  115.     register char *q;
  116.     bool skipping;        /* set if conditionally skipping output */
  117.     bool recurse = FALSE;    /* set if recursion required */
  118.     int i;
  119.     char xbuf[BUFSIZ];
  120.     extern char *macvalue();
  121.  
  122.     if (tTd(35, 24))
  123.     {
  124.         printf("expand(");
  125.         xputs(s);
  126.         printf(")\n");
  127.     }
  128.  
  129.     skipping = FALSE;
  130.     if (s == NULL)
  131.         s = "";
  132.     for (xp = xbuf; *s != '\0'; s++)
  133.     {
  134.         char c;
  135.  
  136.         /*
  137.         **  Check for non-ordinary (special?) character.
  138.         **    'q' will be the interpolated quantity.
  139.         */
  140.  
  141.         q = NULL;
  142.         c = *s;
  143.         switch (c)
  144.         {
  145.           case CONDIF:        /* see if var set */
  146.             c = *++s;
  147.             skipping = macvalue(c, e) == NULL;
  148.             continue;
  149.  
  150.           case CONDELSE:    /* change state of skipping */
  151.             skipping = !skipping;
  152.             continue;
  153.  
  154.           case CONDFI:        /* stop skipping */
  155.             skipping = FALSE;
  156.             continue;
  157.  
  158.           case '\001':        /* macro interpolation */
  159.             c = *++s;
  160.             q = macvalue(c & 0177, e);
  161.             if (q == NULL)
  162.                 continue;
  163.             break;
  164.         }
  165.  
  166.         /*
  167.         **  Interpolate q or output one character
  168.         */
  169.  
  170.         if (skipping || xp >= &xbuf[sizeof xbuf])
  171.             continue;
  172.         if (q == NULL)
  173.             *xp++ = c;
  174.         else
  175.         {
  176.             /* copy to end of q or max space remaining in buf */
  177.             while ((c = *q++) != '\0' && xp < &xbuf[sizeof xbuf - 1])
  178.             {
  179.                 if (iscntrl(c) && !isspace(c))
  180.                     recurse = TRUE;
  181.                 *xp++ = c;
  182.             }
  183.         }
  184.     }
  185.     *xp = '\0';
  186.  
  187.     if (tTd(35, 24))
  188.     {
  189.         printf("expand ==> ");
  190.         xputs(xbuf);
  191.         printf("\n");
  192.     }
  193.  
  194.     /* recurse as appropriate */
  195.     if (recurse)
  196.     {
  197.         expand(xbuf, buf, buflim, e);
  198.         return;
  199.     }
  200.  
  201.     /* copy results out */
  202.     i = buflim - buf - 1;
  203.     if (i > xp - xbuf)
  204.         i = xp - xbuf;
  205.     bcopy(xbuf, buf, i);
  206.     buf[i] = '\0';
  207. }
  208. /*
  209. **  DEFINE -- define a macro.
  210. **
  211. **    this would be better done using a #define macro.
  212. **
  213. **    Parameters:
  214. **        n -- the macro name.
  215. **        v -- the macro value.
  216. **        e -- the envelope to store the definition in.
  217. **
  218. **    Returns:
  219. **        none.
  220. **
  221. **    Side Effects:
  222. **        e->e_macro[n] is defined.
  223. **
  224. **    Notes:
  225. **        There is one macro for each ASCII character,
  226. **        although they are not all used.  The currently
  227. **        defined macros are:
  228. **
  229. **        $a   date in ARPANET format (preferring the Date: line
  230. **             of the message)
  231. **        $b   the current date (as opposed to the date as found
  232. **             the message) in ARPANET format
  233. **        $c   hop count
  234. **        $d   (current) date in UNIX (ctime) format
  235. **        $e   the SMTP entry message+
  236. **        $f   raw from address
  237. **        $g   translated from address
  238. **        $h   to host
  239. **        $i   queue id
  240. **        $j   official SMTP hostname, used in messages+
  241. **        $l   UNIX-style from line+
  242. **        $n   name of sendmail ("MAILER-DAEMON" on local
  243. **             net typically)+
  244. **        $o   delimiters ("operators") for address tokens+
  245. **        $p   my process id in decimal
  246. **        $q   the string that becomes an address -- this is
  247. **             normally used to combine $g & $x.
  248. **        $r   protocol used to talk to sender
  249. **        $s   sender's host name
  250. **        $t   the current time in seconds since 1/1/1970
  251. **        $u   to user
  252. **        $v   version number of sendmail
  253. **        $w   our host name (if it can be determined)
  254. **        $x   signature (full name) of from person
  255. **        $y   the tty id of our terminal
  256. **        $z   home directory of to person
  257. **
  258. **        Macros marked with + must be defined in the
  259. **        configuration file and are used internally, but
  260. **        are not set.
  261. **
  262. **        There are also some macros that can be used
  263. **        arbitrarily to make the configuration file
  264. **        cleaner.  In general all upper-case letters
  265. **        are available.
  266. */
  267.  
  268. define(n, v, e)
  269.     char n;
  270.     char *v;
  271.     register ENVELOPE *e;
  272. {
  273.     if (tTd(35, 9))
  274.     {
  275.         printf("define(%c as ", n);
  276.         xputs(v);
  277.         printf(")\n");
  278.     }
  279.     e->e_macro[n & 0177] = v;
  280. }
  281. /*
  282. **  MACVALUE -- return uninterpreted value of a macro.
  283. **
  284. **    Parameters:
  285. **        n -- the name of the macro.
  286. **
  287. **    Returns:
  288. **        The value of n.
  289. **
  290. **    Side Effects:
  291. **        none.
  292. */
  293.  
  294. char *
  295. macvalue(n, e)
  296.     char n;
  297.     register ENVELOPE *e;
  298. {
  299.     n &= 0177;
  300.     while (e != NULL)
  301.     {
  302.         register char *p = e->e_macro[n];
  303.  
  304.         if (p != NULL)
  305.             return (p);
  306.         e = e->e_parent;
  307.     }
  308.     return (NULL);
  309. }
  310. @
  311.  
  312.  
  313. 5.7.0.1
  314. log
  315. @IDA patches
  316. @
  317. text
  318. @a53 1
  319.     bool quote, inquote, inescape;
  320. a77 1
  321.         quote = FALSE;
  322. a93 3
  323.           case QUOTE822:
  324.             quote = TRUE;
  325.             /*FALLTHROUGH*/
  326. a98 2
  327.             if (quote && !mustquote(q))
  328.                 quote = FALSE;
  329. a107 2
  330.         inquote = FALSE;
  331.         inescape = FALSE;
  332. a116 12
  333.                 if (quote) {
  334.                     if (!inquote) {
  335.                         *xp++ = '"';
  336.                         inquote = TRUE;
  337.                     }
  338.                     if (c == '"' && !inescape)
  339.                         *xp++ = '\\';
  340.                     if (c == '\\')
  341.                         inescape = !inescape;
  342.                     else
  343.                         inescape = FALSE;
  344.                 }
  345. a118 4
  346.             if (inescape && xp < &xbuf[sizeof xbuf - 1])
  347.                 *xp++ = '\\';
  348.             if (quote && xp < &xbuf[sizeof xbuf - 1])
  349.                 *xp++ = '"';
  350. a176 1
  351. **        $k   our UUCP host name, if different from $w
  352. a239 3
  353.         if (p == MACNULL)
  354.             /* shadowing null */
  355.             return (NULL);
  356. a244 31
  357. }
  358. /*
  359. **  MUSTQUOTE -- Check if string contains special RFC-822 chars.
  360. **
  361. **    Parameters:
  362. **        s -- the string to be checked.
  363. **
  364. **    Returns:
  365. **        TRUE if string is in need to be quoted, FALSE otherwise.
  366. **
  367. **    Side Effects:
  368. **        none.
  369. **
  370. **    Does this string contain any characters that RFC 822 says
  371. **    must be quoted?
  372. **    This is not strictly correct, since we consider ' ' non-special.
  373. **    Otherwise we'd quote "My Name", which is just too ugly.
  374. */
  375. mustquote(s)
  376.     register char *s;
  377. {
  378.     register int c;
  379.     extern char *index();
  380.  
  381.     while (c = *s++) {
  382.         c &= 0177;
  383.         if (c <= 037 || c == 0177 ||         /* CTLs */
  384.             index(".()<>@@,;:\\\"[]", c) != NULL)/* 822 specials */
  385.             return TRUE;
  386.     }
  387.     return FALSE;
  388. @
  389.  
  390.  
  391. 5.7.0.2
  392. log
  393. @Deleted declaration of *index() (breaks when index is a #define strchr)
  394. from Bruce Lilly.  Fixed fencepost error in the third expand() argument.
  395. @
  396. text
  397. @d113 1
  398. a113 1
  399.         if (skipping || xp >= &xbuf[(sizeof(xbuf)-1)])
  400. d296 1
  401. @
  402.  
  403.  
  404. 5.7.0.3
  405. log
  406. @Added static bool declaration to mustquote().
  407. @
  408. text
  409. @a57 1
  410.     static bool mustquote();
  411. a291 1
  412. static bool
  413. @
  414.  
  415.  
  416. 5.7.0.4
  417. log
  418. @ANSIfied.
  419. @
  420. text
  421. @a26 6
  422. #ifdef __STDC__
  423. static bool mustquote(const char *);
  424. #else /* !__STDC__ */
  425. static bool mustquote();
  426. #endif /* __STDC__ */
  427.  
  428. a43 1
  429. void
  430. d45 1
  431. a45 1
  432.     const char *s;
  433. d47 1
  434. a47 1
  435.     const char *buflim;
  436. d57 2
  437. a230 1
  438. void
  439. d295 1
  440. a295 1
  441.     register const char *s;
  442. @
  443.  
  444.  
  445. 5.7.0.5
  446. log
  447. @Added RCS ID string
  448. @
  449. text
  450. @a22 1
  451. static char  rcsid[] = "@@(#)$Id$";
  452. @
  453.  
  454.  
  455. 5.7.0.6
  456. log
  457. @Formatting adjustments.
  458. @
  459. text
  460. @d23 1
  461. a23 1
  462. static char  rcsid[] = "@@(#)$Id: macro.c,v 5.7.0.5 1991/04/05 14:55:15 paul Exp paul $";
  463. d133 2
  464. a134 4
  465.                 if (quote)
  466.                 {
  467.                     if (!inquote)
  468.                     {
  469. d306 1
  470. a306 2
  471.     while (c = *s++)
  472.     {
  473. @
  474.  
  475.  
  476. 5.7.0.7
  477. log
  478. @Documented $m macro to be to user list as received.
  479. @
  480. text
  481. @d23 1
  482. a23 1
  483. static char  rcsid[] = "@@(#)$Id: macro.c,v 5.7.0.6 1991/05/18 17:29:02 paul Exp paul $";
  484. a212 1
  485. **        $m   to user before alias expansion
  486. @
  487.